package net.xo68.destiny.starter.manager;

import net.xo68.destiny.core.eventbus.EventBusConfigurer;
import net.xo68.destiny.core.eventbus.EventBusManager;
import net.xo68.destiny.core.eventbus.impl.EventBusManagerImpl;
import net.xo68.destiny.core.lock.DistributedLockManager;
import net.xo68.destiny.core.lock.DistributedLockStore;
import net.xo68.destiny.core.thread.NamedThreadFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({SchedulerManagerProperties.class})
@ConditionalOnProperty(prefix = "destiny.manager", value = "enable",havingValue = "true", matchIfMissing = true)
@ComponentScan(basePackages={"net.xo68.destiny.starter.manager.sched",
        "net.xo68.destiny.starter.manager.worker"})
public class SchedulerManagerConfiguration {



    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Bean
    @ConditionalOnMissingBean(DistributedLockManager.class)
    public DistributedLockManager distributedLockManager(DistributedLockStore distributedLockStore){
        return new DistributedLockManager(distributedLockStore);
    }

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Bean
    @ConditionalOnMissingBean(EventBusManager.class)
    public EventBusManager eventBusManager(EventBusConfigurer eventBusConfigurer){
        return new EventBusManagerImpl(eventBusConfigurer,1024, new NamedThreadFactory("EventBus"));
    }
}
